package com.doujiang.Controller;

import com.doujiang.assistant.Assistant;
import com.doujiang.domain.ChatMessages;
import com.doujiang.tools.tools;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/agent")
@CrossOrigin
@Tag(name = "LLM", description = "Language Model API")
public class AIController {
    @Autowired
    private Assistant assistant;

    @PostMapping(value = "/chat" ,produces = "text/html;charset=utf-8")
    @Operation(summary = "Chat with LLM")
    public Flux<String> chat(@RequestBody ChatMessages chatMessages) {
       return assistant.chat(chatMessages.getMemoryId(),chatMessages.getMessage());
    }

    @PostMapping(value = "/doujiang-chat" ,produces = "text/html;charset=utf-8")
    @Operation(summary = "Chat with Doujiang AI")
    public Flux<String> doujiangChat(@RequestBody ChatMessages chatMessages) {
       System.out.println("=== AI控制器收到请求 ===");
       System.out.println("memoryId: " + chatMessages.getMemoryId());
       System.out.println("message: " + chatMessages.getMessage());
       
       // 设置memoryId到工具类中
       tools.setCurrentMemoryId(chatMessages.getMemoryId());
       
       return assistant.chat(chatMessages.getMemoryId(),chatMessages.getMessage());
    }
}
